package com.hucheng.seckill.entity;

import com.hucheng.seckill.dto.SeckillGoodsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.Date;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 持久层参数
 **/
@Data
public class SeckillGoodsDO {
    private Integer seckillGoodsId;
    private Integer goodsId;
    private BigDecimal seckillPrice;
    private Integer stockCount;
    private Date dateStart;
    private Date dateEnd;
    private Timestamp seckillGoodsDateCreated;
    private Timestamp seckillGoodsDateUpdated;
    private Integer status;

    //秒杀商品
    private String goodsName;
    private String goodsTitle;
    private String goodsImg;
    private String goodsDetail;
    private String goodsPrice;
    private String goodsStock;
    private Timestamp goodsDateCreated;
    private Timestamp goodsDateUpdated;

    public static SeckillGoodsDO buildSeckillGoodsDO(final SeckillGoodsDTO seckillGoodsDTO) {
        if (seckillGoodsDTO != null) {
            SeckillGoodsDO seckillGoodsDO = new SeckillGoodsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(seckillGoodsDTO.getSeckillGoodsId() + "")) {
                seckillGoodsDO.setSeckillGoodsId(seckillGoodsDTO.getSeckillGoodsId());
                seckillGoodsDO.setSeckillGoodsDateCreated(currentTime);
            } else {
                seckillGoodsDO.setSeckillGoodsDateUpdated(currentTime);
            }
            seckillGoodsDO.setGoodsId(seckillGoodsDTO.getGoodsId());
            seckillGoodsDO.setSeckillPrice(seckillGoodsDTO.getSeckillPrice());
            seckillGoodsDO.setStockCount(seckillGoodsDTO.getStockCount());
            seckillGoodsDO.setDateStart(seckillGoodsDTO.getStartDate());
            seckillGoodsDO.setDateEnd(seckillGoodsDTO.getEndDate());
            return seckillGoodsDO;
        }
        return null;
    }
}
